/**    
 * 文件名：Ex6.java    
 *    
 * 版本信息：    
 * 日期：2014年3月25日    
 * xyj 足下 xyj 2014     
 * 版权所有    
 *    
 */
package learn.opencv.chapter02;

import static com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U;
import static com.googlecode.javacv.cpp.opencv_core.cvCreateImage;
import static com.googlecode.javacv.cpp.opencv_core.cvGetSize;
import static com.googlecode.javacv.cpp.opencv_highgui.CV_LOAD_IMAGE_GRAYSCALE;
import static com.googlecode.javacv.cpp.opencv_highgui.cvDestroyWindow;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvNamedWindow;
import static com.googlecode.javacv.cpp.opencv_highgui.cvShowImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvWaitKey;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvCanny;

import com.googlecode.javacv.cpp.opencv_core.IplImage;

/**
 * @项目名称：opencv-test
 * @类名称：Ex6
 * @类描述：
 * @创建人：zhuyi
 * @创建时间：2014年3月25日 下午1:39:52
 * @修改人：zhuyi
 * @修改时间：2014年3月25日 下午1:39:52
 * @修改备注：
 * @version
 * 
 */
public class Ex6 {

    public static void main(String[] args) {

        IplImage image = cvLoadImage("art5014360081-s.jpg", CV_LOAD_IMAGE_GRAYSCALE);

        cvNamedWindow("in");
        cvNamedWindow("out");

        cvShowImage("in", image);

        IplImage out = doCanny(image, 10, 100, 3);

        cvShowImage("out", out);

        cvWaitKey(0);

        cvDestroyWindow("in");
        cvDestroyWindow("out");

    }

    public static IplImage doCanny(IplImage in, double lowThresh, double highThresh, int aperture) {
        if (in.nChannels() != 1) {
            return null;
        }

        IplImage out = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);

        cvCanny(in, out, lowThresh, highThresh, aperture);
        return out;
    }

}
